<?php
session_start();
if($_SERVER['REQUEST_METHOD'] != "POST") {
//if(!isset($_POST['submit'])){
    exit('非法访问!');
}
$username = $_POST['username'];
$password = $_POST['password1'];
$mobile = $_POST['mobile'];

//包含数据库连接文件
include('system/db/conn.php');
//检测用户名是否已经存在
$check_query = mysql_query("select id from do_user where user_name='$username' limit 1");
if(mysql_fetch_array($check_query)){
    echo '错误：用户名 ',$username,' 已存在。<a href="javascript:history.back(-1);">返回</a>';
    exit;
}
$check_query = mysql_query("select id from do_user where mobile='$mobile' limit 1");
if(mysql_fetch_array($check_query)){
    echo '错误： 手机号 ',$mobile,' 已存在。<a href="javascript:history.back(-1);">返回</a>';
    exit;
}
//写入数据
$password = MD5($password);
$regdate = time();
$sql = "INSERT INTO do_user(user_name,user_pwd,mobile,create_time,level_id,group_id,is_effect,is_delete,is_merchant)VALUES('$username','$password','$mobile',
$regdate,1,1,1,0,1)";
if(mysql_query($sql,$conn)){
	$check_query2 = mysql_query("select id from do_user where user_name='$username' and user_pwd='$password' limit 1");
	if($result = mysql_fetch_array($check_query2)){
	    $_SESSION['userid'] = $result['id'];
	}
    $_SESSION['username']=$username;
     $_SESSION['userlevel']=1;
	header('location:index.php');
    //exit('用户注册成功！点击此处 <a href="index.php">首页</a>');
} else {
	//echo '<script language=\"JavaScript\">alert(\"抱歉！添加数据失败:',mysql_error(),'\");</script>'; 
    echo '抱歉！添加数据失败：',mysql_error(),'<br />';
    echo '点击此处 <a href="javascript:history.back(-1);">返回</a> 重试';
}
?>